﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LandandSurvey
{
    public partial class EditAbout : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                landsdbEntities container = new landsdbEntities();
                AboutContent result = (from i in container.AboutContents
                                       select i).ToList().FirstOrDefault();
                if (result != null)
                {
                    txtContent.Text = result.Content;
                }
            }
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            landsdbEntities container = new landsdbEntities();
            AboutContent result = (from i in container.AboutContents
                         select i).ToList().FirstOrDefault();

            if (result == null)
            {
                container.AboutContents.AddObject(new AboutContent() { Content = txtContent.Text });
            }
            else
            {
                result.Content = txtContent.Text;
                container.AboutContents.ApplyCurrentValues(result);
            }
            container.SaveChanges();

            Response.Redirect("About.aspx");
        }
    }
}